#!/usr/bin/env python
#
# Copyright (c) 2011 GhostBSD
#
# See COPYING for licence terms.
#

import os, os.path, sys, stat, shutil

class gbi:
	LICENSE = """    Copyright (c) 2009-2011, GhostBSD
    All rights reserved.

    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions are met:

    1. Redistribution's of source code must retain the above copyright
       notice, this list of conditions and the following disclaimer.

    2. Redistribution's in binary form must reproduce the above copyright
       notice, this list of conditions and the following disclaimer in the
       documentation and/or other materials provided with the distribution.

    3. All advertising materials mentioning features or use of this software
       must display the following acknowledgement:
       This product includes software developed by the GhostBSD and its 
       contributors.

    4. Neither the name of the GhostBSD nor the names of its contributors 
       may be used to endorse or promote products derived from this software
       without specific prior written permission.

    THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' 
    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
    TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 
    PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR
    OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
    USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
    AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
    ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
    POSSIBILITY OF SUCH DAMAGE."""
	
	MSG = """    If you have a to create BSD partition slice. 
	It only can be create on the last slice of you hard drive."""
	CFG = "/root/Desktop/pcinstall.cfg"			     
	print LICENSE
	raw_input ("Press Enter")		
	os.system("rm -f %s " % CFG)
	os.system("touch %s " % CFG)
	f = open('%s' % CFG, 'a')
        f.writelines('installMode=fresh\n')
        f.writelines('installInteractive=no\n')
        f.writelines('installType=FreeBSD\n')
        f.writelines('installMedium=dvd\n')
        f.writelines('packageType=tar\n')
        

        os.system("sh /GhostBSD/pc-sysinstall/pc-sysinstall disk-list")
        DISK = raw_input ("Enter the disk drive you whish to use: ")
        f.writelines('disk0=%s\n' % DISK)
        
        
        INSTALL = raw_input ("Use entire disk %s to install (yes or no): " %  DISK)
        if INSTALL == "yes": 
            f.writelines('partition=all\n')
            BOOT = raw_input ("Boot Manager(bsd or none): ")
            f.writelines('bootManager=%s\n' % BOOT)
            f.writelines('commitDiskPart\n')
	 
            os.system("sh /GhostBSD/pc-sysinstall/pc-sysinstall disk-info %s" % DISK)
            NUMBER = int(raw_input("enter de size: "))
            SWAP = 512
            ROOT = NUMBER - SWAP 
            f.writelines('disk0-part=UFS %s /\n' % ROOT)
            f.writelines('disk0-part=SWAP 0 none\n')
            f.writelines('commitDiskLabel\n')	
        elif INSTALL == "no":
			print MSG
			raw_input ("    Press Enter: ")
			os.system("sh /GhostBSD/pc-sysinstall/pc-sysinstall disk-part %s" % DISK)
			DELETE = raw_input ("Delete partition slice(yes or no): ")
			if DELETE == "yes":
				DELPART = raw_input ("Delete partition slice(s1' s2' s3 or s4): ") 
				os.system("sh /GhostBSD/pc-sysinstall/pc-sysinstall delete-part %s%s" % (DISK, DELPART))
				f.writelines('partition=%s\n' % DELPART)
			BOOT = raw_input ("Boot Manager(bsd or none): ")
			f.writelines('bootManager=%s\n' % BOOT)
			f.writelines('commitDiskPart\n')
			os.system("sh /GhostBSD/pc-sysinstall/pc-sysinstall disk-part %s" % DISK)
			PART = int(raw_input("Enter parttion size: "))
			SWAP = 512
			ROOT = PART - SWAP 
			f.writelines('disk0-part=UFS %s /\n' % ROOT)
			f.writelines('disk0-part=SWAP 0 none\n')
			f.writelines('commitDiskLabel\n')
			os.system("sh /GhostBSD/pc-sysinstall/pc-sysinstall create-part %s%s" % (DISK, PART))
	        
	f.writelines('hostname=GhostBSD\n')
	f.writelines('netDev=AUTO-DHCP\n')
	f.writelines('netSaveDev=AUTO-DHCP\n')
	rootpass = raw_input ("root pasword: ")
	f.writelines('rootPass=%s\n' % rootpass)
	USER = raw_input ("username: ")
	f.writelines('userName=%s\n' % USER)
	NAME = raw_input ("Real Name: ")
	f.writelines('userComment=%s\n' % NAME)
	userpass = raw_input ("User Password: ")
	f.writelines('userPass=%s\n' % userpass)
	SHELL = raw_input ("whish shell you use (sh csh, tcsh, bash, rbash) if you dont know only press Enter[bash default]: ")
	if SHELL == 'sh':
		f.writelines('userShell=/bin/sh\n')
	elif SHELL == 'csh':
		f.writelines('userShell=/bin/csh\n')
	elif SHELL == 'tcsh':
		f.writelines('userShell=/bin/tcsh\n')
	elif SHELL == 'bash':
		f.writelines('userShell=/usr/local/bin/bash\n')
	elif SHELL == 'rbash':
		f.writelines('userShell=/usr/local/bin/rbash\n')
	else:
		f.writelines('userShell=/usr/local/bin/bash\n')
	
	f.writelines('userHome=/home/%s\n' % USER)
	f.writelines('userGroups=wheel,operator\n')
	f.writelines('commitUser\n')
	f.close()
	GINSTALL = raw_input ("Install GhostBSD now(yes or no): ")
	if GINSTALL == "yes":
		os.system("sh /GhostBSD/pc-sysinstall/pc-sysinstall -c %s " % CFG)
		os.system("sh /GhostBSD/GBI/gbi.sh")
	elif GINSTALL == "no":
		quit()	
	
	 

gbi()
    
